package com.example.cinema;

import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;

public class GridViewHeight {

    private GridView gridView;
    private int len;

    public GridViewHeight(GridView gridView, int len) {
        this.gridView = gridView;
        this.len = len;
        init();
    }

    private void init()
    {
        ListAdapter adapter = gridView.getAdapter();
        if(adapter==null)
        {
            return;
        }
        int total = 0;
        int count = adapter.getCount();

        for (int i=0;i<count;i+=len)
        {
            View item = adapter.getView(i,null,gridView);
            item.measure(0,0);
            total += item.getMeasuredHeight()+(gridView.getVerticalSpacing()*4);
        }
        ViewGroup.LayoutParams params = gridView.getLayoutParams();
        params.height = total;
        gridView.setLayoutParams(params);
    }

}
